package com.pj.hellomvvm.ui.fragment

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.pj.common.annotation.LayoutParam
import com.pj.common.base.BaseViewModel
import com.pj.common.base.topbar.BaseTopbarRecyclerFragment
import com.pj.hellomvvm.R
import com.pj.hellomvvm.manager.DataManager
import com.pj.hellomvvm.ui.adapter.TitleIconAdapter
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
@LayoutParam(title = R.string.tab_other)
class OtherFragment : BaseTopbarRecyclerFragment<BaseViewModel>(), OnItemClickListener {

    @Inject
    lateinit var dataManager: DataManager
    @Inject
    lateinit var mAdapter:TitleIconAdapter

    override fun initData(view: View, savedInstanceState: Bundle?) {
        super.initData(view, savedInstanceState)
        mCBinding.recyclerView.layoutManager = GridLayoutManager(requireContext(), 3)
        mAdapter.setList(dataManager.otherItemData)
        mAdapter.setOnItemClickListener(this)
        mCBinding.recyclerView.adapter = mAdapter
    }
    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        val data = mAdapter.data[position]
        Log.d("OtherFragment", "onItemClick: ${data.title}")
        ARouter.getInstance().build("/other/OtherActivity").withString("target", data.title)
            .navigation()
    }

}